package com.evan.blockingqueue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author huangzhongliang
 * @time 2023/07/04 16:11
 */
public class BlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        //    阻塞队列
        ArrayBlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

        //第一组api 阻塞抛异常
        //System.out.println(blockingQueue.add("a"));
        //System.out.println(blockingQueue.add("b"));
        //System.out.println(blockingQueue.add("c"));
        ////System.out.println(blockingQueue.element());
        //
        //
        //System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());
        //System.out.println(blockingQueue.remove());


        //第二组api 阻塞
        //System.out.println(blockingQueue.offer("a"));
        //System.out.println(blockingQueue.offer("b"));
        //System.out.println(blockingQueue.offer("c"));
        ////System.out.println(blockingQueue.offer("d"));
        //
        //System.out.println(blockingQueue.poll());
        //System.out.println(blockingQueue.poll());
        //System.out.println(blockingQueue.poll());
        //System.out.println(blockingQueue.poll());

        //第三组api 超时阻塞
        //System.out.println(blockingQueue.offer("a"));
        //System.out.println(blockingQueue.offer("b"));
        //System.out.println(blockingQueue.offer("c"));
        //
        //System.out.println(blockingQueue.offer("d", 10L, TimeUnit.SECONDS));
        //
        //System.out.println(blockingQueue.poll(10L, TimeUnit.SECONDS));


        //   第四组api-一直阻塞
        //blockingQueue.put("a");
        //blockingQueue.put("b");
        //blockingQueue.put("c");
        //blockingQueue.put("d");


        System.out.println(blockingQueue.take());
        //System.out.println(blockingQueue.take());
        //System.out.println(blockingQueue.take());
        //System.out.println(blockingQueue.take());


    }
}
